# -*- coding: utf-8 -*-
from pdfminer.pdfinterp import PDFResourceManager, process_pdf
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from io import StringIO

def convert_pdf(path, page=1):
	rsrcmgr = PDFResourceManager()
	retstr = StringIO()
	laparams = LAParams()
	device = TextConverter(rsrcmgr, retstr, pageno=page,  laparams=laparams)
	fp = open(path, 'rb')
	process_pdf(rsrcmgr, device, fp)
	fp.close()
	device.close()
	str = retstr.getvalue()
	retstr.close()
	return str
   
file  = r'D:\Users\qiang.qian\Downloads\资产负债表.pdf'
print(convert_pdf(file))


file1 = open('资产负债表.pdf.txt', 'w')
file1.write(convert_pdf(file))
file1.close()